package cn.iocoder.yudao.module.bpm.component;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yomahub.liteflow.core.NodeComponent;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName BaseNodeComponent
 * @Description TODO
 * @Author dingyongze
 * @Date 2024/11/7 11:50
 * @Version 1.0
 */
public class BaseNodeComponent extends NodeComponent {
    @Override
    public void process() throws Exception {

    }

    public String getId() {
        JSONObject jsonObject = this.getContextBean(JSONObject.class);
        return jsonObject.getString("id");
    }

    public void setValue(String key, Object value) {
        JSONObject jsonObject = this.getContextBean(JSONObject.class);
        jsonObject.put(key, value);
    }

    public List<String> getTp() {
        JSONObject jsonObject = this.getContextBean(JSONObject.class);
        JSONArray tp = jsonObject.getJSONArray("tp");
        if (tp != null) {
            return jsonObject.getJSONArray("tp").toJavaList(String.class);
        } else {
            return new ArrayList<>();
        }
    }

    public String getEventType() {
        JSONObject jsonObject = this.getContextBean(JSONObject.class);
        return jsonObject.getString("eventType");
    }

    public boolean isCreateBefore() {
        JSONObject jsonObject = this.getContextBean(JSONObject.class);
        String eventType = jsonObject.getString("eventType");
        String eventTime = jsonObject.getString("eventTime");
        if ("create".equals(eventType) && "before".equals(eventTime)) {
            return true;
        } else {
            return false;
        }
    }

    public boolean isCreateAfter() {
        JSONObject jsonObject = this.getContextBean(JSONObject.class);
        String eventType = jsonObject.getString("eventType");
        String eventTime = jsonObject.getString("eventTime");
        if ("create".equals(eventType) && "after".equals(eventTime)) {
            return true;
        } else {
            return false;
        }
    }

    public boolean isUpdateBefore() {
        JSONObject jsonObject = this.getContextBean(JSONObject.class);
        String eventType = jsonObject.getString("eventType");
        String eventTime = jsonObject.getString("eventTime");
        if ("update".equals(eventType) && "before".equals(eventTime)) {
            return true;
        } else {
            return false;
        }
    }

    public boolean isUpdateAfter() {
        JSONObject jsonObject = this.getContextBean(JSONObject.class);
        String eventType = jsonObject.getString("eventType");
        String eventTime = jsonObject.getString("eventTime");
        if ("update".equals(eventType) && "after".equals(eventTime)) {
            return true;
        } else {
            return false;
        }
    }

    public boolean isSub() {
        JSONObject jsonObject = this.getContextBean(JSONObject.class);
        String string = jsonObject.getString("tableName");
        if ("bpm_oa_apply_sub".equals(string)) {
            return true;
        } else {
            return false;
        }
    }

    public boolean isMain() {
        JSONObject jsonObject = this.getContextBean(JSONObject.class);
        String string = jsonObject.getString("tableName");
        if ("bpm_oa_apply".equals(string)) {
            return true;
        } else {
            return false;
        }
    }




}
